﻿/********************************************************************
	created:	2011/05/12
	created:	12:5:2011   21:04
	filename: 	D:\My Documents\Visual Studio 2010\Projects\IntranetMessager\CommonLibrary\Protocol.cs
	file path:	D:\My Documents\Visual Studio 2010\Projects\IntranetMessager\CommonLibrary
	file base:	Protocol
	file ext:	cs
	author:		
	
	purpose:	各种消息传输格式
*********************************************************************/
using System;

namespace CommonLibrary
{
    [Serializable]
    public class UserInfoClass
    {
        public int UserId { get; set; }
        public string UserName { get; set; }

        public override string ToString()
        {
            return string.Format("{0} ({1})", UserName, UserId);
        }
    }

    public static class Protocol
    {
        #region Nested type: BasicProtocol

        [Serializable]
        public class BasicProtocol
        {
            protected BasicProtocol()
            {
                SendTime = DateTime.Now;
            }

            public int MyUid { get; set; }
            public string MyName { get; set; }
            public DateTime SendTime { get; set; }
        }

        #endregion

        #region Nested type: BroadcastPackage

        [Serializable]
        public class BroadcastPackage : BasicProtocol
        {
            public int[] Receivers { get; set; }
            public string Message { get; set; }
        }

        #endregion

        #region Nested type: DesKeyUpdate

        [Serializable]
        public class DesKeyUpdate : BasicProtocol
        {
            public DesKeyUpdate()
            {
                ServerAnswer = false;
            }

            public bool ServerAnswer { get; set; }
        }

        #endregion

        #region Nested type: DesKeyUpdateAck

        [Serializable]
        public class DesKeyUpdateAck : BasicProtocol
        {
            public DesKeyUpdateAck()
            {
                ServerAnswer = false;
            }

            public string AckKey { get; set; }
            public string AckIv { get; set; }
            public bool ServerAnswer { get; set; }
        }

        #endregion

        #region Nested type: GetNickName

        [Serializable]
        public class GetNickName : BasicProtocol
        {
            public int UidToFind { get; set; }
            public string NickName { get; set; }
        }

        #endregion

        #region Nested type: GetOnlineUsers

        [Serializable]
        public class GetOnlineUsers : BasicProtocol
        {
            public UserInfoClass[] UserInfos { get; set; }
        }

        #endregion

        #region Nested type: GetUid

        [Serializable]
        public class GetUid : BasicProtocol
        {
            public string NameToFind { get; set; }

            public int[] Uids { get; set; }
        }

        #endregion

        #region Nested type: MessageEnvelope

        [Serializable]
        public class MessageEnvelope
        {
            public bool Signed { get; set; }

            public byte[] HashCode { get; set; }

            public int MyUid { get; set; }

            public byte[] ByteMessage { get; set; }

            public Type MessageType { get; set; }
        }

        #endregion

        #region Nested type: RegNewUser

        [Serializable]
        public class RegNewUser : BasicProtocol
        {
            public RegNewUser()
            {
                MyUid = -1;
            }

            public string MyPassword { get; set; }

            public bool Result { get; set; }
        }

        #endregion

        #region Nested type: SignIn

        [Serializable]
        public class SignIn : BasicProtocol
        {
            public string MyPassword { get; set; }

            public bool Result { get; set; }
        }

        #endregion

        #region Nested type: SignOut

        [Serializable]
        public class SignOut : BasicProtocol
        {
        }

        #endregion

        #region Nested type: TalkingPackage

        [Serializable]
        public class TalkingPackage : BasicProtocol
        {
            public int Receiver { get; set; }
            public int Sender { get; set; }
            public string ReceiverName { get; set; }
            public string SenderName { get; set; }
            public string Message { get; set; }
        }

        #endregion
    }
}